﻿using DddCms.Infrastructure.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace DddCms.Infrastructure.Test
{
    /// <summary>
    ///This is a test class for ValidateTest and is intended
    ///to contain all ValidateTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ValidateTest
    {
        public class TestCtx
        {
            public class FakeValidationData
            {
                [StringLengthValidator(5, 50, Ruleset = "test")]
                public string StringValue { get; set; }
            }

            public TestCtx()
            {
                value = new FakeValidationData();
            }
            public FakeValidationData value { get; set; }
        }

        public TestCtx Ctx { get; set; }

        [TestInitialize()]
        public void ValidateTestInitialize()
        {
            Ctx = new TestCtx();
        }

        ///// <summary>
        ///// Validates the valid true test.
        ///// </summary>
        //[TestMethod()]
        //public void ValidateValidFalseTest()
        //{
        //    Validate target = new Validate();

        //    // The false value
        //    Ctx.value.StringValue = "";

        //    try
        //    {
        //        target.Valid<TestCtx.FakeValidationData>(Ctx.value, "test");
        //    }
        //    catch (ValidationValidException ex)
        //    {
        //        Assert.IsTrue(ex.Message.Contains("test"), "The validaition type is not good.");
        //        return;
        //    }
            
        //    Assert.Fail("No exception for invalide object");
        //}
        /// <summary>
        /// Validates the valid true test.
        /// </summary>
        [TestMethod()]
        public void ValidateValidTrueTest()
        {
            Validate target = new Validate();

            // The true value
            Ctx.value.StringValue = "zadazd";

            try
            {
                target.Valid<TestCtx.FakeValidationData>(Ctx.value, "test");
            }
            catch (ValidationValidException)
            {
                Assert.Fail("Exception for valide object");
            }
        }
        /// <summary>
        /// Validates the valid with null param1 test.
        /// </summary>
        [TestMethod()]
        public void ValidateValidWithNullParam1Test()
        {
            Validate target = new Validate();

            Ctx.value.StringValue = "";

            try
            {
                target.Valid<TestCtx.FakeValidationData>(null, "test");
            }
            catch (ValidationNullException ex)
            {
                Assert.IsTrue(ex.Message.Contains("null"), "The validaition type is not good.");
                return;
            }

            Assert.Fail("No exception for invalide null object");
        }
        /// <summary>
        /// Validates the valid with null param2 test.
        /// </summary>
        [TestMethod()]
        public void ValidateValidWithNullParam2Test()
        {
            Validate target = new Validate();

            Ctx.value.StringValue = "";

            try
            {
                target.Valid<TestCtx.FakeValidationData>(Ctx.value, null);
            }
            catch (ValidationNullException ex)
            {
                Assert.IsTrue(ex.Message.Contains("null"), "The validaition type is not good.");
                return;
            }

            Assert.Fail("No exception for invalide null object");
        }

        /// <summary>
        /// Validates the valid with null param2 test.
        /// </summary>
        [TestMethod()]
        public void ValidateNullTest()
        {
            Validate target = new Validate();

            Ctx.value.StringValue = "";

            try
            {
                target.Null(null);
            }
            catch (ValidationNullException ex)
            {
                Assert.IsTrue(ex.Message.Contains("null"), "The validaition type is not good.");
                return;
            }

            Assert.Fail("No exception for invalide null object");
        }
    }
}
